home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
getargs.c
< prev
next >
Wrap
Text File
|
1993-12-14
|
2KB
|
137 lines
#include "crtlocal.h"
#include <Dialogs.h>
enum {
cmdLine = 3, labelLine
};
static struct {
short count;
struct {
Handle h;
Rect box;
char kind;
} item[13];
} itemList = { 4,
/* OK */
0, { 76, 115, 96, 175 }, ctrlItem+btnCtrl,
/* Cancel */
0, { 76, 225, 96, 285 }, ctrlItem+btnCtrl,
/* command line */
0, { 41, 34, 57, 376 }, editText+itemDisable,
/* "Command Line:" */
0, { 14, 20, 30, 170 }, statText+itemDisable,
};
/*
* ditem - return item handle
*
*/
static DialogPtr dp;
static Handle ditem(int);
static Handle ditem(int i)
{
short kind;
Handle item;
Rect box;
GetDItem(dp, i, &kind, &item, &box);
return(item);
}
#pragma parameter __A0 myPtrToHand(__A0,__D0)
pascal Handle myPtrToHand(const void *srcPtr, long size) = 0xA9E3;
enum { NARGS = 255};
static int argc;
static unsigned char **argv;
static Str255 argbuf;
static char *argvec[NARGS+1];
static void parse(char *s, char *t)
{
int c = *s++, quote = 0;
s[(unsigned char)c] = 0;
while (c = *s++) {
if (c == ' ')
continue;
if (argc < NARGS)
argvec[argc++] = t;
do {
if (c == '\\' && *s)
c = *s++;
else if (c == '"' || c == '\'') {
if (!quote) {
quote = c;
continue;
}
if (c == quote) {
quote = 0;
continue;
}
}
*t++ = c;
} while (*s && ((c = *s++) != ' ' || quote));
*t++ = 0;
}
argvec[argc] = 0;
}
static void getargs(void)
{
short i;
Rect bounds = { 60, 51, 170, 461 };
Handle items = myPtrToHand(&itemList,sizeof(itemList));
dp = NewDialog(0, &bounds, "\p line", 0, 1, (WindowPtr) -1, 0, 0, items);
SetCTitle((ControlHandle)ditem(ok), "\pOK");
SetCTitle((ControlHandle)ditem(cancel), "\pCancel");
SetIText(ditem(labelLine), "\pCommand Line:");
SetIText(ditem(cmdLine), "\p" );
SelIText(dp, cmdLine, 9999, 9999);
ShowWindow(dp);
SetCursor(&qd.arrow);
do {
ModalDialog(0, &i);
if (i == cancel) ExitToShell();
}
while (i != ok);
GetIText(ditem(cmdLine), (void *)argbuf);
DisposDialog(dp);
parse((char *)(&argbuf), (char *)(&argbuf));
}
#ifdef THINK_C
void crt_getargs(void);
main()
{
crt_getargs();
}
#define main _main
#endif
void crt_getargs(void)
{
if (!qd.thePort)
{
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitCursor();
InitDialogs(0);
}
getargs();
exit(main(argc, argvec));
}